import { createStore } from "vuex";

//user局部模块 导出  state状态类型  store类型  store为module
import { State as UserState, Store as UserStore, store as user } from "./user";

//根节点状态
export type RootState = {
  user: UserState;
};

//聚合store 给下面的store提供类型
export type Store = UserStore<Pick<RootState, "user">>;

//生成stor示例  定义好类型区分模块
export const store = createStore<RootState>({
  modules: {
    user: user,
  },
});

//重写了 useStore的hook  Store重新定义了返回的类型
//项目中的全部 useStore 使用这个
export function useStore(): Store {
  return store as Store;
}

export default store;
